package com.m1book.domain.book;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

import com.m1book.domain.trace.DonaABookTrace;

/**
 * 此类用于体现每本具体的实体书，也即是{@link Book}的实体纸板拷贝。<br/>
 * 此类中有成员变量donaterId和holderId，分别是最初登记此书的咪书会员的ID和当前持有此书的咪书会员ID。
 * 每一本被登记的ABook都有一个dontater和holder。即ABook和donater是一对一关系，ABook和holder是一对一关系。
 * 当然，donater和holder在此书刚登记还没被其它咪书会员咪去的时候，是同一个人。
 * 
 * @author Frankie
 * @see Book
 *
 */
@Document(collection = "abook")
public class ABook implements Serializable {
	private static final long serialVersionUID = 9051209941040695410L;

	@Id
	private ObjectId id;
	
	@DBRef(collection = "book")
	private Book book;
	
	private Date registerTime;
	private boolean donated;
	private ABookState state;
	
	/**
	 * 这个实体书的咪书网标记，用来可以打印出来贴到这个实体书上的标号
	 */
	private String abookSigning;
	
	@Indexed
	private ObjectId donaterId;
	
	@Indexed
	private ObjectId holderId;
	
	@DBRef(collection = "dona_trace")
	private List<DonaABookTrace> donaTraces;
	
	public ABook() {
		id = ObjectId.get();
		donaTraces = new LinkedList<DonaABookTrace>();
	}

	public ObjectId getId() {
		return id;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public Date getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	public boolean isDonated() {
		return donated;
	}

	public void setDonated(boolean donated) {
		this.donated = donated;
	}

	public ABookState getState() {
		return state;
	}

	public void setState(ABookState state) {
		this.state = state;
	}

	public String getAbookSigning() {
		return abookSigning;
	}

	public void setAbookSigning(String abookSigning) {
		this.abookSigning = abookSigning;
	}

	public ObjectId getDonaterId() {
		return donaterId;
	}

	public void setDonaterId(ObjectId donaterId) {
		this.donaterId = donaterId;
	}

	public ObjectId getHolderId() {
		return holderId;
	}

	public void setHolderId(ObjectId holderId) {
		this.holderId = holderId;
	}

	public List<DonaABookTrace> getDonaTraces() {
		return donaTraces;
	}

	public void setDonaTraces(List<DonaABookTrace> donaTraces) {
		this.donaTraces = donaTraces;
	}

	@Override
	public String toString() {
		return "ABook [id=" + id + ", registerTime=" + registerTime
				+ ", donated=" + donated + ", state=" + state + ", miser="
				+ donaterId + ", book=" + book.getId() + "]";
	}
}
